<?php

if (!defined("EXPONENT")) exit("");

$image = null;
if (isset($_GET['id'])) {
	$image = $db->selectObject("imagegallery_image","id=".$_GET['id']);
}
if (!$image) {
	$image->gallery_id = $_GET['gid'];
}

$gallery = $db->selectObject("imagegallery_gallery","id=".$image->gallery_id);

if ($gallery) {
	$loc = unserialize($gallery->location_data);
	$loc->int = $gallery->id;
	
	if (exponent_permissions_check("manage",$loc)) {
		$form = imagegallery_image::form($image);
		$form->location($loc);
		$form->meta("action","save_image");
		
		$template = new template("imagegallerymodule","_form_editimage",$loc);
		$template->assign("is_edit",(isset($image->id) ? 1 : 0));
		$template->assign("form_html",$form->toHTML());
		$template->output();
	} else {
		echo SITE_403_HTML;
	}
} else {
	echo SITE_404_HTML;
}

?>